<template>
  <div class="login">
    <div class="icon">
      <img src="@/assets/20190425100917895.png">
      <div>西科大二手书城</div>
    </div>
    <div class="form">
    <div class="welcome">
      欢迎登录二手书城
    </div>
      <div class="account">
        <div>账号:</div>
        <input type="text" placeholder="请输入账号" v-model="user.account"></input>
      </div>
      <div class="password">
        <div >密码:</div>
        <input type="password" placeholder="请输入密码" v-model="user.password"></input>
      </div>
      <el-button type="primary" round class="button" @click="login()">登录</el-button>
    </div>
    <div>
    </div>
  </div>
</template>

<script>
import user_api from "@/api/user_api";
export default {
  name: "Login",
  data(){
    return {
      user: {},
    }
  },
  methods:{
    login(){
      user_api.login(this.user).then(res =>{
        if(res.code === 200){
          localStorage.setItem('token',res.data.token)
          localStorage.setItem('isLogin','true')
         this.$store.commit('addUsername',res.data.name)
          this.$store.commit('changeLogin',true)
          this.$router.push('/')
          alert('登录成功')
        }
      }).catch(err=> {
      })
    }
  }
}
</script>

<style scoped lang="css">
.login {
  height: 100%;
  background: linear-gradient(-90deg, #29bdd9 0%, #276ace 100%);
  overflow: hidden;
}
.icon {
  display: flex;
  height: 60px;
  width: 22%;
  margin-top: 100px;
  margin-left: 40%;
  justify-content: space-between;
}
.icon div {
  font-size: 35px;
  margin-top: 30px;
  font-weight: 700;
  margin-right: 60px;
}
.icon img {
  height: 100px;
}
.form {
  margin-left: 38%;
  height: 50%;
  width: 25%;
  margin-top: 70px;
  background-color: rgb(41,186,217);
  border-radius: 40px;
}
.form .welcome {
  font-size: 30px;
  margin: 30px 0 0 130px;
  font-weight: 700;
  color: dodgerblue;
}
.form .account,.password {
  width: 300px;
  margin-left: 100px;
  /*background-color: red;*/
  margin-top: 70px;
}
.form .account div,input {
  text-align: center;
  border-radius: 30px;
  line-height: 40px;
  padding-left: 10px;
  height: 40px;
  font-size: 20px;
  background-color: rgb(229,231,235);
  width: 300px;
  border: 0;
}
.form .password div,input {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 20px;
  border-radius: 30px;
  padding-left: 10px;
  background-color: rgb(229,231,235);
}
.button {
  margin-top: 80px;
  width: 100%;
  /*margin-left: 100px;*/
}
</style>